package cn.djun.news.config;

import cn.djun.news.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author djun
 * @classname InterceptorConfig
 * @description 拦截器配置类
 * @date 2020/11/23 10:15
 * @email 3170495286@qq.com
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    /**
     * 设置拦截哪些路径，不拦截哪些路径。
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
    }

    /**
     * 全局注入拦截器配置Bean
     *
     * @return
     */
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }
}